package org.duncan.sjge.gamedata;

import java.awt.geom.AffineTransform;
import org.duncan.sjge.gamedata.sprites.Sprite;
import org.duncan.sjge.events.CreateEvent;
import org.duncan.sjge.events.DestroyEvent;
import org.duncan.sjge.events.RenderEvent;
import org.duncan.sjge.events.UpdateEvent;
import org.duncan.sjge.interfaces.Creatable;
import org.duncan.sjge.interfaces.Destroyable;
import org.duncan.sjge.interfaces.Renderable;
import org.duncan.sjge.interfaces.Updatable;
import org.duncan.sjge.utils.Vector2;

/**
 *
 * @author Duncan
 */
public class Entity implements Creatable, Updatable, Renderable, Destroyable {
    private Vector2 mPos;
    private Sprite mSprite;
    
    public Entity(final Vector2 pos, final Sprite sprite) {
        mPos    = pos;
        mSprite = sprite;
    }
    
    public Vector2 getPos() {
        return mPos;
    }
    
    public void setPos(final Vector2 pos) {
        mPos = pos;
    }
    
    public Sprite getSprite() {
        return mSprite;
    }
    
    public void setSprite(final Sprite sprite) {
        mSprite = sprite;
    }

    @Override
    public void onCreate(final CreateEvent ev) {}
    
    @Override
    public void onUpdate(final UpdateEvent ev) {}

    @Override
    public void onRender(final RenderEvent ev) {
        if (mSprite != null) {
            final AffineTransform at = new AffineTransform();
            at.translate(mPos.getX(), mPos.getY());
            mSprite.render(ev, at);
        }
    }

    @Override
    public void onDestroy(final DestroyEvent ev) {}

    @Override
    public Updatable getUpdatable() {return this;}

    @Override
    public Renderable getRenderable() {return this;}

    @Override
    public Destroyable getDestroyable() {return this;}

    @Override
    public Creatable getCreatable() {return this;}
}
